<?php
/**
 * Twitter Bootstrap Component
 *
 * This component simple connects twitter bootstrap in project
 *
 * @category  Finlandia_Coctails
 * @author    Evgeny Utehin <utehin@ebola.com.ua>
 * @copyright 2013 Ebola Communications
 * @link      http://www.ebola.com.ua/
 */
class Bootstrap2 extends CApplicationComponent
{
    // const CORE_DIR       = 'dist';
    const PLUGINS_DIR    = 'js';
    const JQUERY_LINK    = '//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js';

    public  $path        = 'application.vendor.bootstrap2';
    public  $jquery;
    private $_coreAssets;

    public function init()
    {
        // $core = Yii::getPathOfAlias($this->path . '.' . self::CORE_DIR);
        $core = Yii::getPathOfAlias($this->path);
        $this->_coreAssets = Yii::app()->assetManager->publish($core);
    }

    public function getJquery()
    {
        if(isset($this->jquery) && !empty($this->jquery)) {
            return $this->jquery;
        } else {
            return self::JQUERY_LINK;
        }
    }

    public function getCoreCss()
    {
        $filename = YII_DEBUG ? 'bootstrap.css' : 'bootstrap.min.css';
        return $this->_coreAssets . '/css/' . $filename;
    }

    public function getCoreJs()
    {
        $filename = YII_DEBUG ? 'bootstrap.js' : 'bootstrap.min.js';
        return $this->_coreAssets . '/js/' . $filename;
    }

    public function getCoreCssTheme()
    {
        $filename = YII_DEBUG ? 'bootstrap-theme.css' : 'bootstrap-theme.min.css';
        return $this->_coreAssets . '/css/' . $filename;
    }

    public function getPluginTransition()
    {
        $pluginFile = 'transition.js';
        return $this->_createPluginAsset($pluginFile);
    }

    public function getPluginModal()
    {
        $pluginFile = 'modal.js';
        return $this->_createPluginAsset($pluginFile);
    }

    public function getPluginDropdown()
    {
        $pluginFile = 'dropdown.js';
        return $this->_createPluginAsset($pluginFile);
    }

    public function getPluginScrollspy()
    {
        $pluginFile = 'scrollspy.js';
        return $this->_createPluginAsset($pluginFile);
    }

    public function getPluginTab()
    {
        $pluginFile = 'tab.js';
        return $this->_createPluginAsset($pluginFile);
    }

    public function getPluginTooltip()
    {
        $pluginFile = 'tooltip.js';
        return $this->_createPluginAsset($pluginFile);
    }

    public function getPluginPopover()
    {
        $pluginFile = 'popover.js';
        return $this->_createPluginAsset($pluginFile);
    }

    public function getPluginAlert()
    {
        $pluginFile = 'alert.js';
        return $this->_createPluginAsset($pluginFile);
    }

    public function getPluginButton()
    {
        $pluginFile = 'button.js';
        return $this->_createPluginAsset($pluginFile);
    }

    public function getPluginCollapse()
    {
        $pluginFile = 'collapse.js';
        return $this->_createPluginAsset($pluginFile);
    }

    public function getPluginCarousel()
    {
        $pluginFile = 'carousel.js';
        return $this->_createPluginAsset($pluginFile);
    }

    public function getPluginAffix()
    {
        $pluginFile = 'affix.js';
        return $this->_createPluginAsset($pluginFile);
    }

    private function _createPluginAsset($pluginFile)
    {
        $pluginPath = Yii::getPathOfAlias($this->path . '.' . self::PLUGINS_DIR);
        $pluginAsset = Yii::app()->assetManager->publish($pluginPath . '/' . $pluginFile);

        return $pluginAsset;
    }
}
